<template>
  <div class="mr-0 overflow-hidden bg-white">
    <BasicTree
      title="组织列表"
      toolbar
      search
      treeWrapperClassName="h-[calc(100%-35px)] overflow-auto"
      :clickRowToExpand="false"
      :treeData="treeData"
      @select="handleSelect"
    />
  </div>
</template>
<script lang="ts">
import { defineComponent, onMounted, ref } from 'vue';
import { BasicTree, TreeItem } from '@/components/Tree';
import { getOrgList } from '@/api/sys/system';
import { AntTreeNodeSelectedEvent } from 'ant-design-vue/lib/tree/Tree';
import { useI18n } from '@/hooks/web/useI18n';

export default defineComponent({
  name: 'DeptTree',
  components: { BasicTree },
  emits: ['select'],
  setup(_, { emit }) {
    const treeData = ref<TreeItem[]>([]);
    async function fetch() {
      treeData.value = (await getOrgList({
        hasDepart: false,
      })) as unknown as TreeItem[];
    }
    function handleSelect(keys: string[], e: AntTreeNodeSelectedEvent) {
      const { node, selected } = e;
      emit('select', selected ? node.id : '');
    }
    onMounted(() => {
      fetch();
    });
    const { t } = useI18n();
    return { treeData, handleSelect, t };
  },
});
</script>
